package com.guangaiboen.attendance.db.service;

import com.github.pagehelper.PageHelper;
import com.guangaiboen.attendance.db.constants.AttendanceConstants;
import com.guangaiboen.attendance.db.dao.AttendanceInfoMapper;
import com.guangaiboen.attendance.db.domain.AttendanceInfo;
import com.guangaiboen.attendance.db.domain.resp.AttendanceInfoResp;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AttendanceInfoService {
    @Resource
    private AttendanceInfoMapper attendanceInfoMapper;

    public void submitDuty(Integer userId,LocalDateTime startTime,LocalDateTime endTime) {
        AttendanceInfo record =new AttendanceInfo();
        record.setStartTime(startTime);
        record.setEndTime(endTime);
        record.setUserId(userId);
        record.setAddTime(LocalDateTime.now());
        record.setUpdateTime(LocalDateTime.now());
        record.setStatus(AttendanceConstants.Valid.YES);
        attendanceInfoMapper.insertSelective(record);
    }

    public List<AttendanceInfoResp> dutyList(String userName, String deptName, String startTime, String endTime, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        Map parameterMap=new HashMap();
        parameterMap.put("userName",userName);
        parameterMap.put("deptName",deptName);
        parameterMap.put("startTime",startTime);
        parameterMap.put("endTime",endTime);
        return attendanceInfoMapper.dutyList(parameterMap);
    }


}
